package com.wbs.batis.rest;


import com.wbs.batis.rest.annotation.EnableRestMapper;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
@ConditionalOnClass({EnableRestMapper.class})
public class BatisRestAutoConfig {


    @Bean
    @ConditionalOnMissingBean(RestInterfaceRegister.class)
    public RestInterfaceRegister interfaceRegister(RequestMappingHandlerMapping requestMappingHandlerMapping, SqlSessionTemplate sqlSessionTemplate){
        return new RestInterfaceRegister(requestMappingHandlerMapping, sqlSessionTemplate);
    }

    @Bean
    @ConditionalOnMissingBean(MapperComponentScanAndRegister.class)
    public MapperComponentScanAndRegister mapperComponentScanAndRegister(RestInterfaceRegister restInterfaceRegister, SqlSessionTemplate sqlSessionTemplate){
        return new MapperComponentScanAndRegister(restInterfaceRegister, sqlSessionTemplate);
    }

}
